/*
 * @FilePath: \flutter_ducafecat_news_getx\lib\pages\application\view.dart
 * @Date: 2022-07-11 14:53:48
 * @LastEditTime: 2022-07-22 15:07:42
 * @Description: 
 */
import 'package:flukit/flukit.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ducafecat_news_getx/common/style/color.dart';
import 'package:flutter_ducafecat_news_getx/common/utils/iconfont.dart';
import 'package:flutter_ducafecat_news_getx/common/values/values.dart';
import 'package:flutter_ducafecat_news_getx/common/widgets/components.dart';
import 'package:flutter_ducafecat_news_getx/common/widgets/widgets.dart';
import 'package:flutter_ducafecat_news_getx/pages/category/index.dart';
import 'package:flutter_ducafecat_news_getx/pages/main/index.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'index.dart';

class ApplicationPage extends GetView<ApplicationController> {
  ///每一行的固定高度
  static const itemHeight = 40;
  final drawerFrist = [
    "我的消息",
    "云贝中心",
    "创作者中心",
  ];
  final drawerFristI = [
    Icon(
      Icons.access_alarms,
      size: 18.sp,
    ),
    Icon(
      Icons.align_vertical_bottom_outlined,
      size: 18.sp,
    ),
    Icon(
      Icons.lightbulb_outline,
      size: 18.sp,
    )
  ];
  final drawerMusic = ["云村有票", "商城", "Beat交易平台", "游戏专区", "口袋彩铃"];
  final drawerMusicI = [
    Icon(
      Icons.access_alarms,
      size: 18.sp,
    ),
    Icon(
      Icons.shopping_cart,
      size: 18.sp,
    ),
    Icon(
      Icons.earbuds_battery_sharp,
      size: 18.sp,
    ),
    Icon(
      Icons.games_outlined,
      size: 18.sp,
    ),
    Icon(
      Icons.music_note,
      size: 18.sp,
    ),
  ];
  final drawerOther = [
    "设置",
    "深色模式",
    "定时关闭",
    "个性装扮",
    "在线听歌免流量",
    "音乐黑名单",
    "青少年模式",
    "音乐闹钟"
  ];
  final drawerOtherI = [
    Icon(
      Icons.settings,
      size: 18.sp,
    ),
    Icon(
      Icons.mode_night_rounded,
      size: 18.sp,
    ),
    Icon(
      Icons.alarm,
      size: 18.sp,
    ),
    Icon(
      Icons.color_lens_outlined,
      size: 18.sp,
    ),
    Icon(
      Icons.queue_music,
      size: 18.sp,
    ),
    Icon(
      Icons.library_music_outlined,
      size: 18.sp,
    ),
    Icon(
      Icons.fiber_manual_record_outlined,
      size: 18.sp,
    ),
    Icon(
      Icons.baby_changing_station_sharp,
      size: 18.sp,
    ),
    Icon(
      Icons.alarm_add_sharp,
      size: 18.sp,
    )
  ];
  final drawerLast = [
    "我的订单",
    "优惠券",
    "我的客服",
    "分享网易云音乐",
    "个人信息收集与使用清单",
    "个人信息第三方共享清单",
    "个人信息与隐私保护",
    "关于"
  ];
  final drawerLastI = [
    Icon(
      Icons.receipt_outlined,
      size: 18.sp,
    ),
    Icon(
      Icons.map_outlined,
      size: 18.sp,
    ),
    Icon(
      Icons.call_end_rounded,
      size: 18.sp,
    ),
    Icon(
      Icons.share_sharp,
      size: 18.sp,
    ),
    Icon(
      Icons.receipt_long,
      size: 18.sp,
    ),
    Icon(
      Icons.shopping_cart_outlined,
      size: 18.sp,
    ),
    Icon(
      Icons.error_outline,
      size: 18.sp,
    ),
    Icon(
      Icons.error_outline,
      size: 18.sp,
    )
  ];

  ///统一滑动
  ScrollController _controller = ScrollController();
// 顶部导航
  AppBar _buildAppBar() {
    return transparentAppBar(
        title: Container(
          height: 40.h,
          width: 260.w,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(20.w)),
            color: AppColors.primaryBackground,
          ),
          child: Text("搜索框"),
        ),
        actions: <Widget>[
          IconButton(
            icon: Icon(
              Iconfont.changge,
              color: AppColors.primaryText,
            ),
            onPressed: () {},
          )
        ]);
  }

  // 内容页
  Widget _buildPageView() {
    return PageView(
      physics: NeverScrollableScrollPhysics(),
      children: <Widget>[
        MainPage(),
        CategoryPage(),
        Text('BookmarksPage'),
        Text('AccountPage'),
        Text('AccountPage'),
      ],
      controller: controller.pageController,
      onPageChanged: controller.handlePageChanged,
    );
  }

  // 底部导航
  Widget _buildBottomNavigationBar() {
    return Obx(() => BottomNavigationBar(
          items: controller.bottomTabs,
          currentIndex: controller.state.page,
          // fixedColor: AppColors.primaryElement,
          type: BottomNavigationBarType.fixed,
          onTap: controller.handleNavBarTap,
          showSelectedLabels: false,
          showUnselectedLabels: false,
        ));
  }

  //底部浮动按钮
  Widget _buildMusic() {
    return Container(
      width: 375.w,
      height: 50.h,
      child: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Container(
            height: 40.h,
            width: 375.w,
            padding: EdgeInsets.symmetric(horizontal: 15.w),
            color: AppColors.cardbg,
            child: Row(
              children: [
                SizedBox(
                  width: 50.h,
                  child: Text('1'),
                ),
                SizedBox(
                  width: 10.w,
                ),
                SizedBox(
                  width: 190.w,
                  child: Text('我去宇宙偷星星，放在夜里等你梵蒂冈地方',
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(letterSpacing: 2.w)),
                ),
                SizedBox(
                  width: 40.h,
                  height: 40.h,
                  child: Stack(
                    children: [
                      Obx(() => GradientCircularProgressIndicator(
                            radius: 18.h,
                            colors: [AppColors.heijiao, Colors.black87],
                            fullColor: AppColors.secondaryElement,
                            value: controller.state.jindu,
                          )),
                      Obx(() => IconButton(
                          onPressed: controller.palyMusic,
                          icon: controller.state.isPlay
                              ? Icon(Icons.pause)
                              : Icon(Icons.headset)))
                    ],
                  ),
                ),
                SizedBox(
                  width: 40.h,
                  child: Icon(Icons.menu),
                )
              ],
            ),
          ),
          Positioned(
            left: 15.w,
            bottom: 0,
            child: Container(
              height: 50.h,
              width: 50.h,
              decoration: BoxDecoration(
                color: AppColors.heijiao,
                borderRadius: BorderRadius.all(Radius.circular(25.h)),
              ),
              child: Center(
                child: RotationTransition(
                  turns: controller.animation,
                  child: Container(
                    height: 30.h,
                    width: 30.h,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.all(Radius.circular(15.h)),
                      color: AppColors.cardbg,
                      image: DecorationImage(
                        image: AssetImage('assets/images/eg_2.png'),
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  //侧边菜单
  Widget _buildDrawer(BuildContext context) {
    return Drawer(
      backgroundColor: AppColors.drawer,
      child: Column(
        children: [
          Container(
              padding: EdgeInsets.fromLTRB(20.w, 40.h, 20.w, 0),
              child: Row(
                children: [
                  Icon(Icons.pages),
                  Text("烟霞生水云"),
                  Icon(
                    Icons.arrow_forward_ios_outlined,
                    size: 16,
                  ),
                  SizedBox(
                    width: 110.w,
                  ),
                  Icon(Iconfont.saoyisao)
                ],
              )),
          Flexible(
            child: ListView(
              controller: _controller,
              padding: EdgeInsets.fromLTRB(15.w, 15.h, 15.w, 15.h),
              children: [
                Container(
                  padding: EdgeInsets.all(15.w),
                  // margin: EdgeInsets.all(7.w),
                  decoration: BoxDecoration(
                      color: AppColors.heijiao,
                      borderRadius: BorderRadius.all(Radius.circular(10.h))),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Text('续费黑胶VIP',
                              style: TextStyle(
                                  color: AppColors.secondaryElement,
                                  fontWeight: FontWeight.bold)),
                          SizedBox(
                            width: 60.w,
                          ),
                          btnTextButtonWidget(
                            buttonText: "会员中心",
                            onPressed: () {},
                          ),
                        ],
                      ),
                      Text("开启会员成长之旅",
                          style: TextStyle(
                              color: AppColors.secondaryElement, fontSize: 12)),
                      Divider(
                        color: AppColors.secondaryElement,
                      ),
                      Row(
                        children: [
                          Text(
                            "受邀专享",
                            style: TextStyle(
                                color: AppColors.thirdElementText,
                                fontSize: 12),
                          ),
                          SizedBox(
                            width: 140.w,
                          ),
                          textTagOne(one: '受邀', two: '专享')
                        ],
                      )
                    ],
                  ),
                ),

                ///第二个框
                Container(
                  // padding: EdgeInsets.all(15.w),
                  margin: EdgeInsets.only(top: 15.w),
                  height: (drawerFrist.length * itemHeight).toInt().h,
                  decoration: BoxDecoration(
                    color: AppColors.primaryBackground,
                    borderRadius: BorderRadius.all(Radius.circular(10.h)),
                  ),
                  child: MediaQuery.removePadding(
                    context: context,
                    removeTop: true,
                    child: ListView.builder(
                      physics: new NeverScrollableScrollPhysics(),
                      itemBuilder: (context, index) => lineCardWidget(
                        icon: drawerFristI[index],
                        onTap: () {},
                        title: drawerFrist[index],
                      ),
                      itemCount: drawerFrist.length,
                    ),
                  ),
                ),

                ///第三个框 音乐服务
                Container(
                  // padding: EdgeInsets.all(15.w),
                  margin: EdgeInsets.only(top: 15.w),
                  height: ((drawerMusic.length + 1) * itemHeight).toInt().h,
                  decoration: BoxDecoration(
                    color: AppColors.primaryBackground,
                    borderRadius: BorderRadius.all(Radius.circular(10.h)),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        padding: EdgeInsets.fromLTRB(20.w, 3.h, 0, 0),
                        child: Text('音乐服务',
                            style: TextStyle(
                                fontSize: 12.sp, color: AppColors.primaryText)),
                      ),
                      Divider(),
                      Container(
                        height: ((drawerMusic.length) * itemHeight).toInt().h,
                        child: MediaQuery.removePadding(
                          context: context,
                          removeTop: true,
                          child: ListView.builder(
                            physics: new NeverScrollableScrollPhysics(),
                            itemBuilder: (context, index) => lineCardWidget(
                              icon: drawerMusicI[index],
                              onTap: () {},
                              title: drawerMusic[index],
                            ),
                            itemCount: drawerMusic.length,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),

                ///第四个框 其他
                Container(
                  // padding: EdgeInsets.all(15.w),
                  margin: EdgeInsets.only(top: 15.w),
                  height: ((drawerOther.length + 1) * itemHeight).toInt().h,
                  decoration: BoxDecoration(
                    color: AppColors.primaryBackground,
                    borderRadius: BorderRadius.all(Radius.circular(10.h)),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        padding: EdgeInsets.fromLTRB(20.w, 3.h, 0, 0),
                        child: Text('其他',
                            style: TextStyle(
                                fontSize: 12.sp, color: AppColors.primaryText)),
                      ),
                      Divider(),
                      Container(
                        height: ((drawerOther.length) * itemHeight).toInt().h,
                        child: MediaQuery.removePadding(
                          context: context,
                          removeTop: true,
                          child: ListView.builder(
                            physics: new NeverScrollableScrollPhysics(),
                            itemBuilder: (context, index) => lineCardWidget(
                              icon: drawerOtherI[index],
                              onTap: () {},
                              title: drawerOther[index],
                            ),
                            itemCount: drawerOther.length,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),

                ///第五个框，最后
                Container(
                  // padding: EdgeInsets.all(15.w),
                  margin: EdgeInsets.only(top: 15.w),
                  height: (drawerLast.length * itemHeight).toInt().h,
                  decoration: BoxDecoration(
                    color: AppColors.primaryBackground,
                    borderRadius: BorderRadius.all(Radius.circular(10.h)),
                  ),
                  child: MediaQuery.removePadding(
                    context: context,
                    removeTop: true,
                    child: ListView.builder(
                      physics: new NeverScrollableScrollPhysics(),
                      itemBuilder: (context, index) => lineCardWidget(
                        icon: drawerLastI[index],
                        onTap: () {},
                        title: drawerLast[index],
                      ),
                      itemCount: drawerLast.length,
                    ),
                  ),
                ),

                ///退出按钮
                Container(
                  margin: EdgeInsets.only(top: 15.w),
                  height: itemHeight.h,
                  decoration: BoxDecoration(
                    color: AppColors.primaryBackground,
                    borderRadius: BorderRadius.all(Radius.circular(10.h)),
                  ),
                  child: TextButton(
                    child: Text(
                      "退出登录/关闭",
                      style: TextStyle(color: Colors.red[600], fontSize: 15.sp),
                    ),
                    onPressed: () {},
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.drawer,
      appBar: MyAppBar(),
      body: Stack(
        children: [
          _buildPageView(),
          Positioned(
            bottom: 0,
            child: _buildMusic(),
          )
        ],
      ),
      drawer: _buildDrawer(context),
      bottomNavigationBar: _buildBottomNavigationBar(),
    );
  }
}
